var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        questionList: [],
        answerList: [],
        questionType: [ "healthySelect", "healthySex", "healthyAge", "healthyHeight", "healthyHeight", "healthyHeight", "healthyHeight" ],
        health_id: 0,
        currentQuestionIndex: 0
    },
    onLoad: function(t) {
        console.log(t.health_id), this.data.health_id = t.health_id;
        var e = decodeURIComponent(t.scene);
        if (e) {
            var a = [];
            a = e.split(",");
            for (var n = 0; n < a.length; n++) {
                var i;
                i = a[n].split("="), console.log(i), "health_id" == i[0] && (this.data.health_id = i[1]);
            }
            console.log(a);
        }
        this.getQualification(this.data.health_id), this.getPaperData(this.data.health_id);
    },
    getQualification: function(t) {
        var a = e.getNetAddresss("plugin.health-assessment.api.index.getQualification");
        e._postNetWork({
            url: a,
            data: {
                health_id: t
            },
            success: function(t) {
                var e = t.data;
                if (1 != e.result) return wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), void setTimeout(function() {
                    wx.navigateBack();
                }, 500);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    sendPost: function() {
        if (this.nextQuestion(!1)) {
            console.log(this.data.answerList);
            var t = this.data, a = t.health_id, n = t.answerList, i = {
                art: "getRecommend"
            }, s = {};
            s.health_id = a;
            for (var o = [], l = [], r = 0; r < n.length; r++) 0 != n[r].type ? o.push(n[r]) : 0 == n[r].type && l.push(n[r]);
            s.basic = o, s.evaluation = l, i.answer_data = s, console.log(i);
            var h = e.getNetAddresss("plugin.health-assessment.api.index.getData");
            e._postNetWork({
                url: h,
                showToastIn: !0,
                data: i,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (wx.redirectTo({
                        url: "/packageE/healthy/healthyResult/healthyResult"
                    }), console.log("提交成功", t)) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    nextQuestion: function() {
        var t = !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0], e = this.data, a = e.questionList, n = e.answerList, i = e.currentQuestionIndex;
        if (1 == a[i].is_require && 0 != a[i].type) {
            if (null == n[i].answer || "" == n[i].answer) return wx.showToast({
                icon: "none",
                title: "该题为必填题",
                duration: 1500
            }), !1;
        } else if (1 == a[i].is_require && 0 == a[i].type && 0 == n[i].option.length) return wx.showToast({
            icon: "none",
            title: "该题为必填题",
            duration: 1500
        }), !1;
        if (!t) return !0;
        this.setData({
            currentQuestionIndex: i + 1
        });
    },
    prveQuestion: function() {
        this.setData({
            currentQuestionIndex: this.data.currentQuestionIndex - 1
        });
    },
    getPaperData: function(t) {
        var a = this, n = e.getNetAddresss("plugin.health-assessment.api.index.getData");
        e._postNetWork({
            url: n,
            showToastIn: !0,
            data: {
                health_id: t,
                art: "getEvaluation"
            },
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var n = e.data.getEvaluation.basic_question, i = e.data.getEvaluation.evaluation_question, s = [];
                    console.log(n, i);
                    for (var o = 0; o < n.length; o++) {
                        var l = {};
                        l.basic_id = n[o].basic_id, l.name = n[o].basic_name, l.type = n[o].type, l.company_name = n[o].company_name, 
                        l.answer = null, s.push(l);
                    }
                    for (var r = 0; r < i.length; r++) {
                        i[r].type = 0;
                        var h = {};
                        h.evaluation_id = i[r].evaluation_id, h.identification = i[r].identification, h.type = 0, 
                        h.option = [], s.push(h);
                    }
                    var u = n.concat(i);
                    console.log(u, s), a.setData({
                        questionList: u,
                        answerList: s
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    quesCallback: function(e) {
        var a = e.detail;
        if (console.log(a), 0 == a.question.type) {
            var n = "answerList[" + a.site + "].option";
            this.setData(t({}, n, a.answer));
        } else {
            var i = "answerList[" + a.site + "].answer";
            this.setData(t({}, i, a.answer));
        }
    }
});